package com.atguigu.gmall.product.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategoryService;
import com.atguigu.gmall.product.vo.CategoryTreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "远程调用-转首页")
@RestController
@RequestMapping("/api/inner/rpc/product")
public class CategoryRpcController {

    @Autowired
    BaseCategoryService baseCategoryService;

    @ApiOperation("获取分类的全部数据并组织成树形结构")
    @GetMapping("/category/tree")
    public Result<List<CategoryTreeVo>> getCategoryTree(){
        List<CategoryTreeVo> treeVos = baseCategoryService.getCategoryTree();
        return Result.ok(treeVos);
    }

    //1、根据三级分类id，得到整个分类的完整路径
    @GetMapping("/category/view/{c3Id}")
    public Result<CategoryTreeVo> getCategoryTreeWithC3Id(@PathVariable("c3Id") Long c3Id){
        CategoryTreeVo vo = baseCategoryService.getCategoryTreeWithC3Id(c3Id);
        return Result.ok(vo);
    };
}
